/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Pacotes;

import Estruturas.Manipuladores;
import Estruturas.ResultSet;
import Opcoes.Conexoes;
import Opcoes.Pacotes;

public class QueryHit extends Header {

    private byte hits;
    private byte[] port;
    private byte[] ipAdrr;
    private byte[] speed;
    private ResultSet[] set;
    private byte[] ident;

    public QueryHit (ResultSet[] resultSet, byte hits)
    {
        super((byte) Pacotes.PAYLOAD_OF_QUERY_HIT, 0);

        this.port = new byte[2];
        this.ipAdrr = new byte[4];
        this.speed = new byte[4];
        this.ident = new byte[16];
        this.hits = hits;
        this.set = resultSet;

    }

    public QueryHit ()
    {
        super((byte) Pacotes.PAYLOAD_OF_QUERY_HIT, 27);

        this.port = new byte[2];
        this.ipAdrr = new byte[4];
        this.speed = new byte[4];
        this.ident = new byte[16];
        this.hits = 0;
        this.set = null;

        this.port = Manipuladores.ShortToByteArray((short) Conexoes.CONNECT_PORT);
        this.ipAdrr = Manipuladores.IPtoByteArray(Manipuladores.getIP());
        this.speed = Manipuladores.intToByteArray(Conexoes.DEFAULT_SPEED);
        this.ident = DadosUsuario.Dados.getServent_id();


    }

    public String make()
    {
        String queryHitPack = "";
        queryHitPack += (char)hits;
        int i;

        
        for(i=0;i<2;i++)
        {
            queryHitPack += (char)port[i];
        }
        for(i=0;i<4;i++)
        {
            queryHitPack += (char)ipAdrr[i];
        }
        for(i=0;i<4;i++)
        {
            queryHitPack += (char)speed[i];
        }
        for(i=0;i<16;i++)
        {
            queryHitPack += (char)ident[i];
        }

        if(set != null)
            for(i=0;i<set.length;i++)
                queryHitPack += set[i].make();

        //
        return makeHeader() + queryHitPack;
    }

}
